package com.addressbook.fw;

public class ContactData implements Comparable<ContactData> {

	private String id;
	private String name;
	private String lastName;
	private String address;
	private String home;
	private String mobile;
	private String work;
	private String email;
	private String email2;
	private String birthDay;
	private String birthMonth;
	private String birthYear;
	private String group;
	private String address2;
	private String home2;

	public ContactData() {
		this.id = null;
		this.name = null;
		this.lastName = null;
		this.address = null;
		this.home = null;
		this.mobile = null;
		this.work = null;
		this.email = null;
		this.email2 = null;
		this.birthDay = null;
		this.birthMonth = null;
		this.birthYear = null;
		this.group = null;
		this.address2 = null;
		this.home2 = null;
	}

	public ContactData(String Name, String LastName, String Address,
			String Home, String Mobile, String Work, String Email,
			String Email2, String day, String month, String year, String group,
			String Address2, String Home2) {
		this.id = "";
		this.name = Name;
		this.lastName = LastName;
		this.address = Address;
		this.home = Home;
		this.mobile = Mobile;
		this.work = Work;
		this.email = Email;
		this.email2 = Email2;
		this.birthDay = day;
		this.birthMonth = month;
		this.birthYear = year;
		this.group = group;
		this.address2 = Address2;
		this.home2 = Home2;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String Name) {
		this.name = Name;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String LastName) {
		this.lastName = LastName;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String Address) {
		this.address = Address;
	}

	public String getHome() {
		return home;
	}

	public void setHome(String Home) {
		this.home = Home;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String Mobile) {
		this.mobile = Mobile;
	}

	public String getWork() {
		return work;
	}

	public void setWork(String Work) {
		this.work = Work;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String Email) {
		this.email = Email;
	}

	public String getEmail2() {
		return email2;
	}

	public void setEmail2(String Email2) {
		this.email2 = Email2;
	}

	public String getBirthDay() {
		return birthDay;
	}

	public void setBirthDay(String day) {
		this.birthDay = day;
	}

	public String getBirthMonth() {
		return birthMonth;
	}

	public void setBirthMonth(String month) {
		this.birthMonth = month;
	}

	public String getBirthYear() {
		return birthYear;
	}

	public void setBirthYear(String year) {
		this.birthYear = year;
	}

	public String getGroup() {
		return group;
	}

	public void setGroup(String group) {
		this.group = group;
	}

	public String getAddress2() {
		return address2;
	}

	public void setAddress2(String Address2) {
		this.address2 = Address2;
	}

	public String getHome2() {
		return home2;
	}

	public void setHome2(String Home2) {
		this.home2 = Home2;
	}

	public ContactData withId(String string) {
		this.id = string;
		return this;
	}

	public ContactData withName(String Name) {
		this.name = Name;
		return this;
	}

	public ContactData withLastName(String LastName) {
		this.lastName = LastName;
		return this;
	}

	public ContactData withAddress(String Address) {
		this.address = Address;
		return this;
	}

	public ContactData withHome(String Home) {
		this.home = Home;
		return this;
	}

	public ContactData withMobile(String Mobile) {
		this.mobile = Mobile;
		return this;
	}

	public ContactData withWork(String Work) {
		this.work = Work;
		return this;
	}

	public ContactData withEmail(String Email) {
		this.email = Email;
		return this;
	}

	public ContactData withEmail2(String Email2) {
		this.email2 = Email2;
		return this;
	}

	public ContactData withBirthDay(String day) {
		this.birthDay = day;
		return this;
	}

	public ContactData withBirthMonth(String month) {
		this.birthMonth = month;
		return this;
	}

	public ContactData withBirthYear(String year) {
		this.birthYear = year;
		return this;
	}

	public ContactData withGroup(String group) {
		this.group = group;
		return this;
	}

	public ContactData withAddress2(String Address2) {
		this.address2 = Address2;
		return this;
	}

	public ContactData withHome2(String Home2) {
		this.home2 = Home2;
		return this;
	}

	@Override
	public int compareTo(ContactData other) {
		if (this.name.toLowerCase().compareTo(other.getName().toLowerCase()) != 0) {
			return this.name.toLowerCase().compareTo(
					other.getName().toLowerCase());
		} else if (this.lastName.toLowerCase().compareTo(
				other.getLastName().toLowerCase()) != 0) {
			return this.lastName.toLowerCase().compareTo(
					other.getLastName().toLowerCase());
		} else {
			// если были добавлены новые контакты с одинаковыми Именами и
			// Фамилиями
			if (this.id == null || this.id.length() == 0) {
				return 1;
			} else if (other.getId() == null || other.getId().length() == 0) {
				return -1;
			} else {
				return this.id.toLowerCase().compareTo(
						other.getId().toLowerCase());
			}
		}
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((email == null) ? 0 : email.hashCode());
		result = prime * result + ((email2 == null) ? 0 : email2.hashCode());
		result = prime * result + ((home == null) ? 0 : home.hashCode());
		result = prime * result + ((lastName == null) ? 0 : lastName.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ContactData other = (ContactData) obj;
		if (email == null) {
			if (other.email != null)
				return false;
		} else if (!email.equals(other.email))
			return false;
		if (email2 == null) {
			if (other.email2 != null)
				return false;
		} else if (!email2.equals(other.email2))
			return false;
		if (home == null) {
			if (other.home != null)
				return false;
		} else if (!home.equals(other.home))
			return false;
		if (lastName == null) {
			if (other.lastName != null)
				return false;
		} else if (!lastName.equals(other.lastName))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "ContactData [id=" + id + ", name=" + name + ", lastName="
				+ lastName + ", address=" + address + ", home=" + home
				+ ", mobile=" + mobile + ", work=" + work + ", email=" + email
				+ ", email2=" + email2 + ", birthDay=" + birthDay
				+ ", birthMonth=" + birthMonth + ", birthYear=" + birthYear
				+ ", group=" + group + ", address2=" + address2 + ", home2="
				+ home2 + "]";
	}

	public ContactData correctionContact() {
		String str = name;
		name = lastName;
		lastName = str;
		if (email.length() == 0
				&& email2.length() != 0) {
			email = email2;
			email2 = "";
		}
		if (home.length() == 0) {
			if (mobile.length() != 0) {
				home = mobile;
			} else if (work.length() != 0) {
				home = work;
			}
		}
		return this;
	}
}